
#include "process_list.h"

typedef struct mem {
    PAGE *page;
    struct mem *previous;
    struct mem *next;
} MEMORY;

// Initializes a memory linked list
MEMORY *memoryCreate();

// Checks if it's a empty list
bool memoryEmpty(MEMORY *memory);

// Link a new element at the end of a circular list
bool memoryInsert(MEMORY **memory, PAGE *page);

// Prints all elements of a linked list
void memoryPrint(MEMORY *memory);

// Read a process page from memory
bool memoryRead(PROCESS *processList, MEMORY **memory, int memorySize, int processId, int pageNumber);

// Write on a process page from memory
bool memoryWrite(PROCESS *processList, MEMORY **memory, int memorySize, int processId, int pageNumber);

// Remove an memory structure element from a memory circular list
void memoryRemove(MEMORY **memory, MEMORY *frame);

// Remove all pages of a process from the memory
PROCESS *procRemove(PROCESS **processList, MEMORY **memory, int processId);

// Find the number of elements of an existing memory structure
int memorySize(MEMORY *memory);

// Push a memory element to the end of the list
void updateMemoryPosition(MEMORY **memory, MEMORY *address);

// Least recently used second chance algorithm to pick a victm page
void lruSecondChance(MEMORY **memory, int ramSize);
